﻿#include "cell.h"
#include <QBrush>

Cell::Cell(int wX, int wY, QColor color)
{
    rect = new QGraphicsRectItem(wX, wY, 50, 50);
    rect->setBrush(QBrush(color));

    cap = new QGraphicsTextItem();
    cap->setFont(QFont("Times", 20, QFont::Bold));
    cap->setPos(QPoint(wX + 10, wY + 10));

    ans = new QGraphicsTextItem();
    ans->setPos(wX+ 20, wY + 20);
    ans->setFont(QFont("Helvetica [Cronyx]", 20, QFont::Bold));
    ans->setDefaultTextColor(QColor("#ff0000"));
    ans->hide();

    colorname = color.name();
    X = wX;
    Y = wY;

    msgBox = new QInputDialog();
    connect(msgBox, SIGNAL(accepted()), this, SLOT(insertChar()));
}

void Cell::getChar(int key, QString str)
{
    //word-wrap
    msgBox->setInputMode(QInputDialog::TextInput);
    msgBox->setMaximumWidth(500);
    msgBox->setLabelText(QString::fromUtf8("Ký tự cho ô: %1\n").arg(key).append(str));
    msgBox->setTextValue(msgBox->textValue());
    msgBox->exec();
}

void Cell::insertChar()
{
    cap->setPlainText(msgBox->textValue().toUpper().at(0));
}

Cell::~Cell()
{
    rect->~QGraphicsRectItem();
    cap->~QGraphicsTextItem();
    ans->~QGraphicsTextItem();
    msgBox->~QInputDialog();
}
